﻿using System;
using System.Threading;

namespace _171_excel_sheet_column_number
{
    class Program
    {
        static void Main (string[] args)
        {
            Console.WriteLine (TitleToNumber("ZY"));
            Console.WriteLine (TitleToNumber("AB"));
            Console.WriteLine (TitleToNumber("A"));
            Console.WriteLine (TitleToNumber("BA"));
        }

        public static int TitleToNumber (string s)
        {
            int num = 0;

            //if (s.Length == 1) return s[0] - 'A' + 1;

            for (int i = 0;i < s.Length;i++)
            {
                num += (s[i] - 'A' + 1) * (int)Math.Pow (26, s.Length - i - 1);
                //if (s.Length - i - 1 == 0)
                //    num += s[i] - 'A' + 1;
                //else

            }
            return num;
        }
    }
}
